package tmproject.hlhj.fhp.anwser.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import tmproject.hlhj.fhp.anwser.R

/**
 * Created by Never Fear   on 2018\8\21 0021.
Never More....
 */
class OptionAdp(private val datas:ArrayList<String>) :BaseQuickAdapter<String,BaseViewHolder>(R.layout.option_item,datas){
    var rightOption:Int?=0
    var canClick=true
    var listener:ChooseOptionListener?=null
    override fun convert(helper: BaseViewHolder?, item: String?) {
        val itemTv = helper?.getView<TextView>(R.id.itemTv)
        itemTv?.text=item!!

        itemTv?.let {
            it.setBackgroundResource(R.drawable.option_item_un)
            helper?.setVisible(R.id.itemIcon,false)
            it.setTextColor(Color.parseColor("#333333"))
            it.setOnClickListener {
                if (!canClick)return@setOnClickListener
                canClick=false
                itemTv.setTextColor(Color.parseColor("#ffffff"))
                if (helper?.adapterPosition==rightOption){
                    itemTv.setBackgroundResource(R.drawable.option_item_right)
                    helper?.setImageResource(R.id.itemIcon,R.drawable.ic_dt_zhengque)
                    helper?.setVisible(R.id.itemIcon,true)
                    listener?.right()
                }else{
                    itemTv.setBackgroundResource(R.drawable.option_item_wrong)
                    listener?.wrong()
                    helper?.setVisible(R.id.itemIcon,true)
                    helper?.setImageResource(R.id.itemIcon,R.drawable.ic_dt_cuowu)
                }
            }
        }
    }

    interface ChooseOptionListener{
        fun right()
        fun wrong()
    }
}